include makefile.mk

LIB_DIR=$(patsubst %,-L %,$(LIB_DIRS))
# INC_DIR=$(patsubst %,-I %,$(SCREEN_DIRS))
INC_DIR= $(patsubst %,-I %,$(INC))
INC_DIR+=$(patsubst %,-I %,$(SRC_DIRS))

SRC_FILE=$(foreach N, $(SRC_DIRS),$(wildcard $(N)/*.c))
COMPILE_FILE=${addprefix $(OUTPUTIDR)/,$(SRC_FILE:.c=.o)}

CFLAGS += -Wall -Wno-format-extra-args -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Werror=implicit-int  -Werror=enum-compare -Werror=return-type -Werror=parentheses\
			-Wno-implicit-function-declaration -Wformat=0 -Wno-comment \
			-Wno-unused-variable -Wno-pointer-sign -Wno-unused-but-set-variable -Wno-unused-function -Wno-unused-value
CFLAGS += -g $(LIB_DIR) -lrt -lpthread -lm -lmosquitto -ldl -lfyaml


all:CREATE_PATH
	@make $(TARGET_NAME).bin
	@echo $(PROJECT_TYPE)
ifdef PROJECT_TYPE
	@cp ../mapTable/log.mapTab $(TARGET_DIR)/$(SOFTWARE_VER)_$(BUILD_TIME).mapTab
endif

	@echo "====================================== success ======================================"
	@ls -lh $(TARGET_NAME).bin
	@ls -lh $(LIB_NAME)
	# @ls -lh $(TARGET_NAME).dump
	# @ls -lh $(TARGET_NAME).S
ifdef PROJECT_TYPE
	@echo $(TARGET_DIR)/$(SOFTWARE_VER)_$(BUILD_TIME).mapTab
endif
	@echo "====================================================================================="
	cp $(TARGET_NAME).bin ./sys_manager.bin

CREATE_PATH:
	@mkdir -p $(OUTPUTIDR)
	@mkdir -p $(TARGET_DIR)
	@mkdir -p $(patsubst %,$(OUTPUTIDR)/%,$(SCREEN_DIRS) $(SRC_DIRS))


$(OUTPUTIDR)/%.o: %.c
	$(CC) -c $< -o $@  $(CFLAGS) $(INC_DIR)

$(TARGET_NAME).bin:$(COMPILE_FILE)
	$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
	# $(OBJDUMP) -x -s $@ > $(TARGET_NAME).dump
	# $(OBJDUMP) -S $@ > $(TARGET_NAME).S


clean:
	$(RM) -rf ./zout
	# $(RM) -rf $(OUTPUTIDR)	$(TARGET_DIR)


run:
	sudo gdb $(TARGET_NAME).bin
